/*
   @Copyright:LeetCode
   @Author:   tjyemail
   @Problem:  http://leetcode.com/problems/add-binary
   @Language: C++
   @Datetime: 19-07-02 11:07
   */

class Solution {
public:
	string addBinary(string &a, string &b) {
		int la=a.length(), lb=b.length();
		string s(max(la,lb)+1,'0');
		for(int i=la, j=lb, k=s.length(), c=0; i || j || c; c>>=1){
			if(i) c+=a[--i]-'0';
			if(j) c+=b[--j]-'0';
			s[--k]='0'+(c&1);
		}
		if(s[0]=='0') s.erase(0,1);
		return s;
	}
};
